/*
 * 本代码功能为用ESP32模拟蓝牙鼠标在安卓手机上滑屏
 * 滑屏时间为3-10S随机，可以修改
 * 会有一定概率无法滑动，暂时不知道怎么修改。
 */

#include <BleMouse.h>

int ttt;
BleMouse bleMouse("ESP32蓝牙鼠标","Espressif",100);
 
void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
  bleMouse.begin();
}
     
void xxx(){
    unsigned long startTime;
    Serial.println("按住左键");
    bleMouse.press(MOUSE_LEFT);           
    delay(220);                           
    Serial.println("Move mouse pointer up");  
    startTime = millis();
    while(millis()<startTime+190) {        
      bleMouse.move(0,-50);                
      delay(19);                           
    }
    Serial.println("释放左键");
    bleMouse.release(MOUSE_LEFT);         
    delay(220);
    Serial.println("Move mouse pointer down");
    startTime = millis();
    while(millis()<startTime+190) {
      bleMouse.move(0,50);
      delay(19);
    }
}
void loop() {
  if(bleMouse.isConnected()) {
     ttt = random(3000,10000);       //随机时间
     xxx();   
     Serial.println("延迟随机时间");
     delay(ttt);
   }
 }